package top.mh.mybatis.sqlsession;

import top.mh.mybatis.config.XMLConfigBuilder;
import top.mh.mybatis.pojo.Configuration;

import java.io.InputStream;

/**
 * @author mh
 * @version 1.0
 * @description sqlSessionFactory工厂构建
 * @since 2024/2/2 15:31
 */
public class SqlSessionFactoryBuilder {

    /**
     * 1.解析配置文件，封装Configuration 2.创建SqlSessionFactory工厂对象
     * @return
     */
    public SqlSessionFactory build(InputStream inputStream) throws Exception {
        // 1.创建xml configuration配置文件解析对象
        XMLConfigBuilder xmlConfigurationBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigurationBuilder.parse(inputStream);
        // 2.创建sqlSessionFactory对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return sqlSessionFactory;
    }
}
